home *** CD-ROM | disk | FTP | other *** search
- import java.util.Calendar;
-
- public class CalendarCalc {
- private Calendar cal_actual;
- private int year_actual;
- private int month_actual;
- private int day_actual;
- private int hour_actual;
- private int minute_actual;
- private int second_actual;
- private Calendar cal_1;
- private int year_1;
- private int month_1;
- private int day_1;
- private int hour_1;
- private int minute_1;
- private int year_2;
- private int month_2;
- private int day_2;
- private int hour_2;
- private int minute_2;
- private int result_year;
- private long result_month;
- private long result_week;
- private long result_day;
- private long result_hour;
- private long result_minute;
- private long result_second;
- private String[] wochentage = new String[8];
-
- public CalendarCalc(int year1, int month1, int day1, int hour1, int minute1) throws NumberFormatException {
- try {
- this.wochentage[1] = new String("Sonntag");
- this.wochentage[2] = new String("Montag");
- this.wochentage[3] = new String("Dienstag");
- this.wochentage[4] = new String("Mittwoch");
- this.wochentage[5] = new String("Donnerstag");
- this.wochentage[6] = new String("Freitag");
- this.wochentage[7] = new String("Samstag");
- this.year_1 = year1;
- this.month_1 = month1;
- this.day_1 = day1;
- this.hour_1 = hour1;
- this.minute_1 = minute1;
- this.cal_1 = Calendar.getInstance();
- this.cal_1.set(1, this.year_1);
- this.cal_1.set(2, this.month_1 - 1);
- this.cal_1.set(5, this.day_1);
- this.cal_1.set(11, this.hour_1);
- this.cal_1.set(12, this.minute_1);
- } catch (NumberFormatException nfe) {
- throw nfe;
- }
- }
-
- private void calculate() {
- this.cal_actual = Calendar.getInstance();
- this.result_second = Math.abs((this.cal_actual.getTime().getTime() - this.cal_1.getTime().getTime()) / 1000L);
- this.result_minute = this.result_second / 60L;
- this.result_hour = this.result_minute / 60L;
- this.result_day = this.result_hour / 24L;
- this.result_week = this.result_day / 7L;
- this.result_year = Math.abs(this.cal_actual.get(1) - this.year_1);
- this.result_month = (long)Math.abs(12 - this.month_1 + this.month_actual + 11 + (this.result_year - 1) * 12);
- }
-
- public String getResultString() {
- this.calculate();
- new String();
- String nl = new String("\n");
- String result = "Der Abstand zu heute beträgt:" + nl + "in Sekunden: " + nl + this.result_second + nl + "in Minuten: " + nl + this.result_minute + nl + "in Stunden: " + nl + this.result_hour + nl + "in Tagen: " + nl + this.result_day + nl + "in Wochen: " + nl + this.result_week + nl + "in Monaten: " + nl + this.result_month + nl + "in Jahren: " + nl + this.result_year + nl + "Wochentag:" + nl + this.wochentage[this.cal_1.get(7)];
- return result;
- }
- }
-